package ftp.main;

import java.io.IOException;
import java.util.Scanner;

import ftp.ClientConnection;
import ftp.FTP_User;
import ftp.IClient;
import ftp.datalay.FTP_Response;

public class Client {

	public static void main(String[] args) {
		
		FTP_User client = new FTP_User(new ClientConnection("192.168.0.129", 21));
		String username = "ftplogin";
		String password = "hej1234";
		Scanner sc = new Scanner(System.in);
		String menu = "start";
		// Der oprettes forbindelse
			try {
				client.open();
				System.out.println(client.getReply().getResponseMessage());
				FTP_Response response = null;
				System.out.println("login: " + client.login(username, password));
				response = client.send("PWD");
				System.out.println(response.getResponseMessage());
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		// MENU
		while(!menu.toUpperCase().equals("Q")){
			System.out.println("-====MENU====-");
			System.out.println("[L]ist files");
			System.out.println("[Q]uit");
			System.out.println("[T]ransfer file");
			System.out.println("[G]et log files");
			menu = sc.nextLine();
			try {
				if(menu.toUpperCase().equals("L"))
					client.listFiles();
				else if(menu.toUpperCase().equals("G"))
					client.downloadFile("log.txt");
				else if(menu.toUpperCase().equals("T")){
					client.listFiles();
					System.out.println("skriv filnavn");
					client.downloadFile(sc.nextLine());
				}
			} catch (IOException e) {
				System.out.println(e.getMessage());
				e.printStackTrace();
			}
		}
		
		// programmet lukkes ordentligt
		try {
			client.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				
	}

}
